<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title></title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <script src="js/boot.js"></script>
    <link rel="stylesheet" href="plugins/layuiadmin/style/admin.css" media="all">
    <link rel="stylesheet" href="plugins/layuiadmin/style/login.css" media="all">
</head>

<body>
    <div class="login-container">
        <div class="login-weaper">
            <div class="login-left">
                <p class="title" id="systemName"></p>
                <div style="margin-top: 20px;display: flex;justify-content: center;align-items: center;width: 400px;">
                    <img style="height: 150px;width: 150px;" src="favicon_main.png">
                    <div style="font-size: 25px;display: flex;flex-direction: column;align-items: center;justify-content: center;margin-left: 50px;">
                        <span>扬帆起航</span>
                        <span style="margin-top: 20px;">乘风破浪</span>
                    </div>
                </div>
            </div>
            <div class="login-right">
                <div class="layadmin-user-login-box layadmin-user-login-body layui-form">
                    <div class="layadmin-user-login-box layadmin-user-login-header" style="margin-top: -20px;">
                        <h4>登录系统</h4>
                    </div>
                    <div class="layui-form-item">
                        <label class="layadmin-user-login-icon layui-icon layui-icon-username" for="loginName"></label>
                        <input type="text" id="loginName" lay-verify="required" placeholder="用户名" class="layui-input">
                    </div>
                    <div class="layui-form-item">
                        <label class="layadmin-user-login-icon layui-icon layui-icon-password" for="password"></label>
                        <input type="password" id="password" lay-verify="required" placeholder="密码" class="layui-input">
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-row">
                            <div class="layui-col-xs7">
                                <label class="layadmin-user-login-icon layui-icon layui-icon-vercode" for="validateCode"></label>
                                <input type="text" id="validateCode" lay-verify="required" placeholder="图形验证码" class="layui-input">
                            </div>
                            <div class="layui-col-xs5">
                                <div style="margin-left: 10px;">
                                    <img src="" class="layadmin-user-login-codeimg" id="validateCodeImage" onclick="BindValidateCode()">
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item" style="margin-bottom: 20px;">
                        <input type="checkbox" id="rememberPassword" lay-skin="primary" title="记住密码">
                    </div>
                    <div class="layui-form-item">
                        <button class="layui-btn layui-btn-primary layui-border-green layui-btn-fluid" lay-submit lay-filter="LAY-user-login-submit" onclick="UserAuth()">立 即 登 录</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script>
        layui.config({
            base: 'plugins/layuiadmin/' //静态资源所在路径
        }).extend({
            index: 'lib/index' //主入口模块
        })
    </script>
    <script>
        var validateKey = "";
        var AnonymousAccess = false;
        $(function() {
            BindProjectConfig();
            BindValidateCode();
            CheckRemember();
            BindPageInfo();
        })

        function BindValidateCode() {
            validateKey = GetNewGuid();
            var param = {
                key: validateKey
            };
            HttpPost(JSON.stringify(param), "/frame/validatecode/getValidateCode", function(result, status) {
                if (result.code == 0) {
                    $("#validateCodeImage").attr("src", result.data.obj);
                }
            })
        }

        function UserAuth() {
            var validateparam = {
                key: validateKey,
                validteCode: $("#validateCode").val()
            };
            HttpPost(JSON.stringify(validateparam), "/frame/validatecode/checkValidateCode", function(result, status) {
                if (result.code == 0) {
                    UserLogin();
                } else {
                    OpenFailMessage(result.msg);
                    BindValidateCode();
                    $("#validateCode").val("");
                }
            })
        }

        function UserLogin() {
            BindRemember();
            var param = {
                loginName: $("#loginName").val(),
                password: BootMD5($("#loginName").val() + "|" + $("#password").val())
            };
            HttpPost(JSON.stringify(param), "/system/common/auth/userLogin", function(result, status) {
                if (result.code == 0) {
                    SetTokenID(result.data.token);
                    SetTokenModel(result.data.tokenModel);
                    window.location.href = GetRootPath() + "index.html";
                } else {
                    OpenFailMessage(result.msg)
                }
            })
        }

        function BindRemember() {
            var check = $('#rememberPassword').prop('checked');
            SetCookie(cookieRemember, check, 90);
            if (check) {
                SetCookie(cookieLoginName, $("#loginName").val(), 90);
                SetCookie(cookiePassword, $("#password").val(), 90);
            }
        }

        function CheckRemember() {
            var check = $.cookie(cookieRemember);
            if (check) {
                $("#rememberPassword").attr("checked", true);
                $("#loginName").val($.cookie(cookieLoginName));
                $("#password").val($.cookie(cookiePassword));
                layui.form.render();
            }
        }

        function BindPageInfo() {
            var config = GetProjectConfig();
            $("#systemName").text(config.systemName);
        }
    </script>
</body>

</html>